<?php
	if($_POST['submit']){
		$f1 = $_POST['username'];//邮箱或者电话,验证以后可以登陆
		$f2 = $_POST['password'];

		$f3 = $_POST['remember'];

		if($f1==''){
			$result_info = '用户名不能为空';
		}else if($f2==''){
			$result_info = '密码不能为空';
		}
		if(!$result_info){
			require_once("./includes/configure.php");
			require_once("./includes/database.php");
			$db = Database::Connect();
			$sql = "SELECT * FROM ask_user WHERE username='".$db->Encode($f1)."'";//这里需要跟客户确定。
		    $row = $db->GetSingleRow($sql);
		    if(!$row)
		    {
		    	$result_info ="不存在用户:".$f1;
		    }else{
				if(md5($f2)===$row->password){

					session_start();
					//登陆成功
					 $_SESSION['user_id'] = $row->uid;
					 $_SESSION['user_name'] = $row->username;

					 if($f3 == "on"){
					 setcookie('uid',$_SESSION['user_id'],time()+3600*24);
					 setcookie('uname',$_SESSION['user_name'],time()+3600*24);

					 }else if(isset($_COOKIE['uid'])){
					 	setcookie('uid',$_SESSION['user_id'],time()-3600);
					    setcookie('uname',$_SESSION['user_name'],time()-3600);
					 	}

					  echo "<script>location='index.php';</script>";
				}else{
					$result_info ="密码错误";

				}
		    }
		    $db->Close();
		}
	}
?>
<div id="content">
<div class="member_cont">
<div id="regMainContainer">
<div id="caption">
<table cellpadding="0" cellspacing="0" border="0">
	<tbody>
		<tr>
			<td valign="top">用户登陆</td>
		</tr>
	</tbody>
</table>
</div>
<style>
.reg_div p{
	margin-top: 3px;
}
.reg_div p .my_login_submit_new{
	margin-left: 90px;
    margin-top: 10px;
}
.reg_div span{
	display:block;
	width:90px;
	float:left;
	font-size:14px;
	text-align: right;
	padding-top: 3px;
}
</style>
<form id="reg_form" name="reg_form"
	action="wenda/?user/login.html" method="post">
<input type="hidden" name="myForward" id="myForward" value="1">
<div style="padding-top:10px;padding-left:120px;" class="reg_div">
	<p style="color: gray;    font-size: larger;    font-weight: bold;    padding-bottom: 20px;    padding-left: 17px;"><?php echo $result_info?></p>
	<p><span>用户名：</span><input class="inputname" type="text" name="username" size="20"
				id="username" maxlength="16" value=""></p>
	<p><span>密码：</span><input class="inputpwd" type="password" name="password" size="20"
				id="password" maxlength="16" value=""></p>
	<p><input class="my_login_submit_new" value=""
			type="submit" name="my_register_submit">
	   <input type="hidden" name="submit" value="提交注册"></p>
</div>
</form>
</div>
<div id="regSideContainer">
<dl class="tips">
	<dt>注册房客网您可以：</dt>
	<dd>网上找房买房，轻松操作</dd>
	<dd>定制找房条件，自动匹配</dd>
	<dd>房价即时变化，一手掌握</dd>
	<dd>小区新鲜房源，一网打尽</dd>
	<dd>业主委托卖房，简单快捷</dd>
</dl>
<div class="title">&gt; <a href="./zhuce.php">立即注册</a></div>
</div>
</div>
</div>
